﻿<div style="width:600px;margin:0 auto;padding-top:20px;">
    <form class="layui-form" action="">
        <div class="layui-form-item">
        	<label class="layui-form-label">类型(必填)</label>
            <div class="layui-input-block">
                <select id="type" name="type" win-verify="required" lay-filter="type">
					<option value="uncode-single-task">单个任务</option>
					<option value="uncode-multi-main-task">分布式任务</option>
				</select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">bean名称(必填)</label>
            <div class="layui-input-block">
                <input type="text" name="targetBean" placeholder="请输入任意SpringBean的名称" autocomplete="off" win-verify="required" class="layui-input" />
            </div>
        </div>
        
        <div class="layui-form-item" id="beforeMethod">
            <label class="layui-form-label">before方法名称</label>
            <div class="layui-input-block">
                <input type="text" name="beforeMethod" placeholder="请输入集群任务数据获取方法，返回值必须为List类型，单任务无该项" autocomplete="off" class="layui-input" />
            </div>
        </div>
        
        <div class="layui-form-item">
            <label class="layui-form-label">执行方法名称(必填)</label>
            <div class="layui-input-block">
                <input type="text" name="targetMethod" placeholder="请输入Bean的任务执行方法名称" autocomplete="off" win-verify="required" class="layui-input" />
            </div>
        </div>
        
        <div class="layui-form-item" id="afterMethod">
            <label class="layui-form-label">after方法名称</label>
            <div class="layui-input-block">
                <input type="text" name="afterMethod" placeholder="集群任务在所有节点目标方法执行完成后执行该方法" autocomplete="off" class="layui-input" />
            </div>
        </div>
        
        <div class="layui-form-item">
            <label class="layui-form-label">corn表达式</label>
            <div class="layui-input-block">
                <input type="text" name="cronExpression" placeholder="请输入corn表达式" autocomplete="off"  class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">启动时间间隔period(毫秒)</label>
            <div class="layui-input-block">
                <input type="text" name="period" placeholder="请输入两次任务启动时间之间的间隔时长,period与delay不能同时填" autocomplete="off"  class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">结束时间间隔delay(毫秒)</label>
            <div class="layui-input-block">
                <input type="text" name="delay" placeholder="请输入上次任务结束时间与下次任务开始时间之间的间隔时长,period与delay不能同时填" autocomplete="off"  class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开始时间</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="startTime" name="startTime" win-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">参数(字符串)</label>
            <div class="layui-input-block">
                <input type="text" name="params" placeholder="请输入方法参数,目前只支持字符串,建议json" autocomplete="off"  class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item" id="threadNum">
            <label class="layui-form-label">线程数量</label>
            <div class="layui-input-block">
                <input type="text" name="threadNum" value="1" placeholder="请输入集群任务线程数量" autocomplete="off"  class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">后缀</label>
            <div class="layui-input-block">
                <input type="text" name="extKeySuffix" placeholder="请输入后缀,同一方法要起多个任务时使用" autocomplete="off"  class="layui-input" />
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="winui-btn" lay-submit lay-filter="formAddMenu">确定</button>
                <button class="winui-btn" onclick="winui.window.close('addMenu'); return false;">取消</button>
            </div>
        </div>
    </form>
</div>
<script>
    layui.use(['form','layer','laydate'], function (form) {
        var $ = layui.$, msg = winui.window.msg;
        var laydate = layui.laydate;
        
        laydate.render({
        	elem: '#startTime',
        	type: 'datetime'
        });
        
        hiddenInputs();
        
        var selectData = {};
		form.render();
		
		//添加select的监听事件
	    form.on('select(type)', function(data) { //no是那个lay-filter的值
			var nos = $("#type").val();//获得选中的option的值
			console.log(nos);//没啥用
			hiddenInputs();
			if(nos == "uncode-multi-main-task"){
				$("#beforeMethod").show();
				$("#afterMethod").show();
				$("#threadNum").show();
			}
		});

		form.on('submit(formAddMenu)', function(data) {
			//表单验证
			if (winui.verifyForm(data.elem)) {
				layui.$.ajax({
					type : 'post',
					url : '/task/add',
					contentType : 'application/json;charset=utf-8',
					data : JSON.stringify(data.field),
					dataType : 'json',
					success : function(json) {
						if (json.success) {
							msg('添加成功');
						} else {
							msg(json.message)
						}
						winui.window.close('addMenu');
					},
					error : function(xml) {
						msg('添加失败');
						console.log(xml.responseText);
					}
				});
			}
			return false;
		});
		
		function hiddenInputs(){
			$("#beforeMethod").hide();
			$("#afterMethod").hide();
			$("#threadNum").hide();
		}
	});
</script>